package com.yunshan.welfare;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yunshan.common.annotation.Log;
import com.yunshan.common.core.controller.BaseController;
import com.yunshan.common.core.domain.AjaxResult;
import com.yunshan.common.enums.BusinessType;
import com.yunshan.welfare.domain.WelfareCoupon;
import com.yunshan.welfare.service.IWelfareCouponService;
import com.yunshan.common.utils.poi.ExcelUtil;
import com.yunshan.common.core.page.TableDataInfo;

/**
 * 优惠券管理Controller
 *
 * @author yunshan
 * @date 2025-01-20
 */
@Api(tags = "优惠券管理")
@RestController
@RequestMapping("/welfare/coupon")
public class WelfareCouponController extends BaseController
{
    @Autowired
    private IWelfareCouponService welfareCouponService;

    /**
     * 查询优惠券管理列表
     */
    @ApiOperation("查询优惠券管理列表")
    @PreAuthorize("@ss.hasPermi('welfare:coupon:list')")
    @GetMapping("/list")
    public TableDataInfo list(WelfareCoupon welfareCoupon)
    {
        startPage();
        List<WelfareCoupon> list = welfareCouponService.selectWelfareCouponList(welfareCoupon);
        return getDataTable(list);
    }

    /**
     * 查询优惠券管理列表（不分页）
     */
    @ApiOperation("查询优惠券管理列表")
    @PreAuthorize("@ss.hasPermi('welfare:coupon:list')")
    @GetMapping("/query")
    public AjaxResult query(WelfareCoupon welfareCoupon)
    {
        List<WelfareCoupon> list = welfareCouponService.selectWelfareCouponList(welfareCoupon);
        return success(list);
    }

    /**
     * 导出优惠券管理列表
     */
    @ApiOperation("导出优惠券管理列表")
    @PreAuthorize("@ss.hasPermi('welfare:coupon:export')")
    @Log(title = "优惠券管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WelfareCoupon welfareCoupon)
    {
        List<WelfareCoupon> list = welfareCouponService.selectWelfareCouponList(welfareCoupon);
        ExcelUtil<WelfareCoupon> util = new ExcelUtil<WelfareCoupon>(WelfareCoupon.class);
        util.exportExcel(response, list, "优惠券管理数据");
    }

    /**
     * 获取优惠券管理详细信息
     */
    @ApiOperation("获取优惠券管理详细信息")
    @PreAuthorize("@ss.hasPermi('welfare:coupon:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(welfareCouponService.selectWelfareCouponById(id));
    }

    /**
     * 新增优惠券管理
     */
    @ApiOperation("新增优惠券管理")
    @PreAuthorize("@ss.hasPermi('welfare:coupon:add')")
    @Log(title = "优惠券管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WelfareCoupon welfareCoupon)
    {
        return toAjax(welfareCouponService.insertWelfareCoupon(welfareCoupon));
    }

    /**
     * 修改优惠券管理
     */
    @ApiOperation("修改优惠券管理")
    @PreAuthorize("@ss.hasPermi('welfare:coupon:edit')")
    @Log(title = "优惠券管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WelfareCoupon welfareCoupon)
    {
        return toAjax(welfareCouponService.updateWelfareCoupon(welfareCoupon));
    }

    /**
     * 删除优惠券管理
     */
    @ApiOperation("删除优惠券管理")
    @PreAuthorize("@ss.hasPermi('welfare:coupon:remove')")
    @Log(title = "优惠券管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(welfareCouponService.deleteWelfareCouponByIds(ids));
    }
}
